public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class PrintingExample
{
private Font printFont;
private StreamReader streamToPrint;
static string filePath;


public PrintingExample()
{
Printing();
}

// The PrintPage event is raised for each page to be printed.
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
float xPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
printFont = new Font("Arial", 5+i);
xPos = i * 5 + leftMargin;
yPos = topMargin + (i * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString("PrintedString", printFont, Brushes.Black,
xPos, yPos, new StringFormat());
ev.HasMorePages = false;
}

// Print the file.
public void Printing()
{
try
{
streamToPrint = new StreamReader(filePath);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);


// this is for 5 inch width and 5 inch height paper.
pd.Document.DefaultPageSettings.PaperSize = new PaperSize("Custom",500,500);

// Print the document.
pd.Print();
}
finally
{
streamToPrint.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

// This is the main entry point for the application.
public static void Main(string[] args)
{
filePath = @"..\..\TextFile1.txt";
new PrintingExample();
}
}
}

